<template>
  <div>
    <el-card shadow="hover">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="姓名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="性别">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option label="男" value="man"></el-option>
            <el-option label="女" value="women"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生年月">
          <el-col :span="11">
            <el-date-picker
              type="date"
              placeholder="选择日期"
              v-model="form.birthDate"
              style="width: 100%"
            ></el-date-picker>
          </el-col>
        </el-form-item>
       
      </el-form>
      <div>新增填充信息项</div>
      
    </el-card>
     <div style="text-align:center">
<el-button style="height: 50px; width: 100px;margin-top:20px" type="primary" @click="onSubmit()">文书生成</el-button>
     </div>
    
  </div>
</template>

<script>
import {exportWord} from '@/api/tool.js'
export default {
  data() {
    return {
      form: {
        name: "",
        sex: "",
        birthDate: ""
       
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
      console.log(this.form)
      exportWord(this.form.name,this.form.sex,this.form.birthDate).then(
        (res)=>{

           let blob = new Blob([res.data], {
          type: "application/msword;charset=UTF-8",
        }); //规定文件类型 res就是返回你的数据流了
        let link = document.createElement("a");
        // link.download = fileName//a标签添加属性
        let objectUrl = URL.createObjectURL(blob);
        link.setAttribute("href", objectUrl);

        link.setAttribute("download", "文书生成示例");
        link.click();
        //释放内存
        window.URL.revokeObjectURL(link.href);

        }
      )
    },
  },
};
</script>